﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace Reconciliation.Data
{
    public partial class Log
    {

        private static void LogEntry(string title, string message)
        {
            try
            {
                LogEntry le = new LogEntry();
                le.TimeStamp = System.DateTime.Now;
                le.Categories.Add("Audit");
                le.Message = message;
                le.EventId = 1;
                le.Title = title;
                le.Priority = 1;
                Logger.Write(le);
            }
            catch (Exception ex)
            {
            }
        }

        public static string FormatMessage(Exception ex)
        {
            string msg = "Message : " + (ex.Message == null ? "" : ex.Message) + ", ";
            msg += "Inner Exception : " + (ex.InnerException == null ? "" : ex.InnerException.ToString()) + ", ";
            msg += "Stack Trace : " + ex.StackTrace == null ? "" : ex.StackTrace + ", ";
            msg += "Source : " + (ex.Source == null ? "" : ex.Source);
            return msg;
        }

        public static void LogEntryOnException(string title, Exception ex)
        {
            Log.LogEntry(title, FormatMessage(ex));
        }
    }
}
